package dao.util;

public class JDBCDateHelper 
{

  public static java.sql.Date toSqlDate(java.util.Date date) 
  {
	  date = killUtilNanos(date);
    return new java.sql.Date(date.getTime());
  }

  public static java.sql.Time toSqlTime(java.util.Date date) 
  {
	  date = killUtilNanos(date);
    return new java.sql.Time(date.getTime());
  }

  public static java.sql.Timestamp toSqlTimestamp(java.util.Date date) 
  {
	  date = killUtilNanos(date);
    return new java.sql.Timestamp(date.getTime());
  }

  public static java.util.Date toDate(java.sql.Date date) 
  {
    return new java.util.Date(date.getTime());
  }

  public static java.util.Date toDate(java.sql.Time time) 
  {
    return new java.util.Date(time.getTime());
  }

  public static java.util.Date toDate(java.sql.Timestamp timestamp) 
  {
	  timestamp = killSqlNanos(timestamp);
    return new java.util.Date(timestamp.getTime());
  }

  public static java.util.Date killUtilNanos(java.util.Date date)
  {
	  java.sql.Timestamp timeStamp = new java.sql.Timestamp(date.getTime());
	  timeStamp.setNanos(0);
	  date.setTime(timeStamp.getTime());
	  return date;
  }

  public static java.sql.Timestamp killSqlNanos(java.sql.Timestamp timeStamp)
  {
	  timeStamp.setNanos(0);
	  return timeStamp;
  }
}